package priv.yiyuan.example.design.chain;

/**
 * 账号校验
 *
 * @author YiYuan
 * @data 2025/10/11
 * @apoNote
 */
public class AccountValidationCommand extends AbstractLoginCommand {

    @Override
    protected boolean process(LoginContext context) {

        System.out.println("正在校验账号: " + context.getUsername());

        if (context.getUsername().equals("admin") && context.getPassword().equals("123456")) {
            context.setAccountValid(true);
            System.out.println("√ 账号校验成功。");
            return true;
        }

        else if (context.getUsername().equals("guest") && context.getPassword().equals("guest")) {
            context.setAccountValid(true);
            System.out.println("√ 账号校验成功(访客)。");
            return true;
        }
        else {
            context.setErrorMessage("用户名或密码错误。");
            return false;
        }

    }
}
